using Gateway.Common.Entity;
using Gateway.Common.Extensions;

namespace Gateway.Domain.Entities;

/// <summary>
/// 上传文件的数据表
/// </summary>
public class UploadFiles : AggregateRootEntityBase
{
    public UploadFiles(long length = default,
        string originName = default, string extName = default)
    {
        FileNo = FileNoExtension.GenerateNumber();
        Length = length;
        ExtInfo = string.Empty;
        Hash = "";
        Path = "Local/" + DateTime.Now.ToString("yyyyMMdd") + "/" + FileNo + "." + extName;
        OriginName = originName;
        IsTemp = false;
        StorageKey =  "local";
    }

    /// <summary>
    /// 设置路径
    /// </summary>
    /// <param name="path"></param>
    public void SetPath(string path)
    {
        Path = path;
    }

    /// <summary>
    /// 完成，代表着临时文件转换为正式文件
    /// </summary>
    public void Finish()
    {
        IsTemp = true;
    }

    /// <summary>
    /// 文件号
    /// </summary>
    public string FileNo { get; set; }

    /// <summary>
    /// 文件大小
    /// </summary>
    public long Length { get; set; }

    /// <summary>
    /// 文件扩展信息
    /// </summary>
    public string ExtInfo { get; set; }

    /// <summary>
    /// 文件hash
    /// </summary>
    public string Hash { get; set; }

    /// <summary>
    /// 完整存储路径
    /// </summary>
    public string Path { get; set; }

    /// <summary>
    /// 原文件名
    /// </summary>
    public string OriginName { get; set; }

    /// <summary>
    /// 是否是临时文件
    /// </summary>
    public bool IsTemp { get; set; }

    /// <summary>
    /// 存储来源 local 本地 其他的归属为 oss 的 key
    /// </summary>
    public string StorageKey { get; set; }

    public UploadFiles()
    {
    }
}